﻿using System;

namespace DBMock.Validators.Attributes
{
    /// <summary>
    /// 验证器特性基类
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
    public class BaseValidatorAttribute : ValidatorAttribute
    {
        protected Type type; //validatro类型
        protected object[] para; //validator构造函数参数

        /// <summary>
        /// 初始化BaseValidatorAttribute
        /// </summary>
        /// <param name="validatorType">验证器类型</param>
        /// <param name="validatorParams">验证器构造参数</param>
        public BaseValidatorAttribute(Type validatorType, params object[] validatorParams)
        {
            type = validatorType;
            para = validatorParams;
        }

        public override Validator GetValidator()
        {
            if (type == null)
                return null;

            return Activator.CreateInstance(type, para) as Validator;
        }
    }
}
